<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.pethospital.service.impl.PetServiceImpl" %>
<%@ page import="com.pethospital.service.PetService" %>
<%@ page import="com.pethospital.entity.Pet" %>
<%@ page import="com.pethospital.entity.User" %>
<%@ page import="java.util.List" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
    <title>宠物数据调试页面</title>
    <meta charset="UTF-8">
</head>
<body>
    <h1>宠物数据调试页面</h1>
    
    <%
        // 获取当前用户
        User currentUser = (User) session.getAttribute("currentUser");
        out.println("<h2>当前用户信息:</h2>");
        if (currentUser != null) {
            out.println("用户ID: " + currentUser.getUserId() + "<br>");
            out.println("用户名: " + currentUser.getUsername() + "<br>");
            out.println("真实姓名: " + currentUser.getRealName() + "<br>");
            out.println("用户类型: " + currentUser.getUserType() + "<br>");
        } else {
            out.println("当前用户为空，请先登录<br>");
        }
        
        out.println("<hr>");
        
        // 测试宠物服务
        PetService petService = new PetServiceImpl();
        
        out.println("<h2>所有宠物数据:</h2>");
        List<Pet> allPets = petService.getAllPets();
        if (allPets != null && !allPets.isEmpty()) {
            out.println("总共找到 " + allPets.size() + " 只宠物:<br>");
            for (Pet pet : allPets) {
                out.println("- ID: " + pet.getPetId() + ", 名称: " + pet.getPetName() + 
                           ", 类型: " + pet.getPetType() + ", 主人ID: " + pet.getOwnerId() + "<br>");
            }
        } else {
            out.println("没有找到任何宠物数据<br>");
        }
        
        out.println("<hr>");
        
        if (currentUser != null) {
            out.println("<h2>当前用户的宠物:</h2>");
            List<Pet> myPets = petService.getPetsByOwnerId(currentUser.getUserId());
            if (myPets != null && !myPets.isEmpty()) {
                out.println("找到 " + myPets.size() + " 只宠物:<br>");
                for (Pet pet : myPets) {
                    out.println("- ID: " + pet.getPetId() +
                               ", 名称: '" + pet.getPetName() + "'" +
                               ", 类型: '" + pet.getPetType() + "'" +
                               ", 品种: '" + pet.getBreed() + "'" +
                               ", 性别: '" + pet.getGender() + "'" +
                               ", 年龄: " + pet.getAge() + "个月" +
                               ", 主人ID: " + pet.getOwnerId() + "<br>");
                }

                // 测试前端渲染
                out.println("<h3>前端选择框测试:</h3>");
                out.println("<select>");
                out.println("<option value=''>请选择宠物</option>");
                for (Pet pet : myPets) {
                    out.println("<option value='" + pet.getPetId() + "'>" +
                               pet.getPetName() + " (" + pet.getPetType() + ")</option>");
                }
                out.println("</select>");

            } else {
                out.println("当前用户没有宠物数据<br>");
            }
        }
        
        out.println("<hr>");
        
        // 测试特定用户ID的宠物
        out.println("<h2>测试用户ID 2 的宠物:</h2>");
        List<Pet> user2Pets = petService.getPetsByOwnerId(2);
        if (user2Pets != null && !user2Pets.isEmpty()) {
            out.println("用户ID 2 有 " + user2Pets.size() + " 只宠物:<br>");
            for (Pet pet : user2Pets) {
                out.println("- ID: " + pet.getPetId() + ", 名称: " + pet.getPetName() + 
                           ", 类型: " + pet.getPetType() + "<br>");
            }
        } else {
            out.println("用户ID 2 没有宠物数据<br>");
        }
        
        out.println("<hr>");
        
        // 测试特定用户ID的宠物
        out.println("<h2>测试用户ID 3 的宠物:</h2>");
        List<Pet> user3Pets = petService.getPetsByOwnerId(3);
        if (user3Pets != null && !user3Pets.isEmpty()) {
            out.println("用户ID 3 有 " + user3Pets.size() + " 只宠物:<br>");
            for (Pet pet : user3Pets) {
                out.println("- ID: " + pet.getPetId() + ", 名称: " + pet.getPetName() + 
                           ", 类型: " + pet.getPetType() + "<br>");
            }
        } else {
            out.println("用户ID 3 没有宠物数据<br>");
        }
    %>
    
    <hr>
    <p><a href="${pageContext.request.contextPath}/appointment/add">返回预约页面</a></p>
    <p><a href="${pageContext.request.contextPath}/pages/common/login.jsp">登录页面</a></p>
</body>
</html>
